package com.drg.center.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.drg.center.entity.param.SysPositionListDTO;
import com.drg.center.mapper.SysPositionMapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import com.drg.center.entity.SysPositionPO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

/**
 * @Author: zhangxilin
 * @Date: 2024/4/23
 */
@Repository
public class SysPositionDAO extends BaseDAO<SysPositionMapper, SysPositionPO> {

    public Boolean isExist(String position, Long excludeId){
        LambdaQueryWrapper<SysPositionPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SysPositionPO::getPosition, position);
        lambdaQueryWrapper.ne(excludeId !=null, SysPositionPO::getId, excludeId);
        return getBaseMapper().selectCount(lambdaQueryWrapper) >0? true: false;
    }

    public IPage<SysPositionPO> findPage(SysPositionListDTO param){
        LambdaQueryWrapper<SysPositionPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(StringUtils.isNotBlank(param.getPosition()), SysPositionPO::getPosition, param.getPosition());
        lambdaQueryWrapper.orderByDesc(SysPositionPO::getCreateTime);
        return getBaseMapper().selectPage(new Page<>(param.getPageIndex(), param.getPageSize()),lambdaQueryWrapper);
    }
}
